package com.lmx.repoDomain.repository;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.lmx.common.constants.CommonConstants;
import com.lmx.persistence.service.AssessmentService;
import com.lmx.repoDomain.exception.BusinessException;
import com.lmx.repoDomain.tmodel.Assessment;

import io.katharsis.repository.annotations.JsonApiResourceRepository;

/**
 * 员工考核
 *
 * @author ytche
 * @date 2017年6月28日
 *
 */
@Component
@JsonApiResourceRepository(Assessment.class)
public class AssessmentRepository extends BaseRepository<Assessment> {
	@Autowired
	private AssessmentService service;

	@PostConstruct
	public void init() {
		dslJpaService.setEntityClass(Assessment.class);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Assessment save(Assessment entity) {
		if (entity.getExaminer() == null || entity.getExamTime() == null
				|| entity.getType() == null) {
			throw new BusinessException(
					CommonConstants.ASSESSMENT_ERROR.ASSESSMENT_INFO_LACK
							.lable(),
					null, "信息不足");
		}
		return this.service.save(entity);
	}
}
